#include <iostream>
#include "deck.h"

class FlipGame
{
  public:
   FlipGame();
   void playFlip();


  private:
   DeckOfCards deck;
   int score;
   bool readChoice() const;
   void determineScore (const card &dealtCard);
};


FlipGame::FlipGame ()
:deck()
{
   score=0;
}

bool FlipGame::readChoice() const
{
   char choice;
   cout << "Do you want to keep playing (y/n)?" << endl;
   cin >> choice;
   if (choice == 'y')
      return true;
   else if (choice == 'n')
      return false;
   else 
      throw baseException ("You must enter either y or n");
}

void FlipGame::playFlip ()
{
   card topCard;
   //shuffle deck three times
   for (int i=0; i<4; i++)
      deck.shuffle();

   topCard = deck.dealCard();
   cout << topCard << endl;

   bool keepPlaying=readChoice();
   determineScore(topCard);
  
   while ( keepPlaying && !deck.isEmpty() )
   {
      topCard = deck.dealCard();
      cout << endl << "Your score : " << score << endl;
      cout << topCard << endl;
      keepPlaying=readChoice();
      determineScore(topCard);
   }

   cout << endl << "All done! Your final score is : " << score <<endl;

}

void FlipGame::determineScore (const card &dealtCard)
{
   int suit = dealtCard.getSuit();
   int value = dealtCard.getValue();

   switch (value)
   {
      case 1 : score+=10; break;
      case 2 : score=0; break;
      case 3 : score=0; break;
      case 4 : score=0; break;
      case 5 : score=0; break;
      case 6 : score=0; break;
      case 7 : score=score/2; break;
      case 8 : score=score; break;
      case 9 : score=score; break;
      case 10 : score=score; break;
      case 11 : score+=5; break;
      case 12 : score+=5; break;
      case 13 : score+=5; break;
      case 14 : score+=10; break;
   }
   
   switch(suit)
   {
      //Hearts
      case 2 : score+=1; break;
   }
  

}


